/**
 * 
 */
package com.trungsi.mydict.server.controller;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author trungsi
 *
 */
@Controller
public class FileUploadController {

	@RequestMapping(value="/upload")
	public ModelAndView handleUpload(@RequestParam("file") MultipartFile file) {
		ModelAndView mav = new ModelAndView("show");
		try {
			byte[] input = file.getBytes();
			BufferedReader reader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(input)));
			String line;
			while ((line = reader.readLine()) != null) {
				
			}
			String message = new String(input);
			System.out.println(message);
			mav.addObject("message", message);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return mav;
	}
}
